package com.cmj.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 这是注释
 */
@Slf4j
@Aspect
@Component
public class TestAspect {
    //1.确定切点
    @Pointcut("@annotation(com.cmj.annotation.SystemLog)")
    public void pt(){};

    //2.设置通知方法
    @Around("pt()")
    public void printPt(ProceedingJoinPoint joinPoint){
        try {
            //前置通知
            handlerBefore();
            //方法执行
            Object jp = joinPoint.proceed();
            //后置通知
            handlerAfter();
        } catch (Throwable e) {
            e.printStackTrace();
            log.info("这是异常通知");
        } finally {
            log.info("这是最终通知");
        }
    }

    private void handlerAfter() {
        log.info("这是前置通知");
    }

    private void handlerBefore() {
        log.info("这是后置通知");
    }

}
